@echo off
echo =============================================
echo DivinationMaster Build Script
echo =============================================

echo [1/4] Setting network timeout...
set GRADLE_OPTS=-Dorg.gradle.daemon=false -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000

echo [2/4] Cleaning project...
call .\gradlew clean --no-daemon --refresh-dependencies

echo [3/4] Building with domestic mirrors...
call .\gradlew assembleDebug --no-daemon --refresh-dependencies --stacktrace

IF %ERRORLEVEL% NEQ 0 (
    echo.
    echo Build failed. Possible solutions:
    echo 1. Run download-dependencies.bat to manually download dependencies
    echo 2. Check network connection and proxy settings
    echo 3. Try offline mode
    exit /b 1
)

echo [4/4] Build successful!
if exist "app\build\outputs\apk\debug\app-debug.apk" (
    echo APK file generated successfully
    for %%I in ("app\build\outputs\apk\debug\app-debug.apk") do echo   File size: %%~zI bytes
) else (
    echo APK file not found
)

echo.
echo Build completed!
pause
